package io.dy.compose;

import io.dy.utils.CommonUtils;

import java.util.concurrent.CompletableFuture;

/**
 * @author dmj
 * @date 2024年03月02日 下午3:02
 * 编排两个有依赖关系的任务
 */
public class ThenCompose {

    public static CompletableFuture<String> futureArray(String filePath){
        return CompletableFuture.supplyAsync(()->{
            CommonUtils.printThreadLog("文件读取。。。");
            String futureArray = CommonUtils.readFile(filePath);
            return futureArray;
        });
    }

    public static void main(String[] args) {
        CompletableFuture<String> stringCompletableFuture = futureArray("dy.txt").thenCompose(content -> {
            return CompletableFuture.supplyAsync(() -> {
                return content + ",dy";
            });
        });
    }
}
